
#ifndef TIMEZONE_H_
#define TIMEZONE_H_
/**
 * Timezone.h
 *
 *  Created on: Oct 21, 2011
 *      Author: Thom Hehl
 *      This is public domain. Use as you please.
 */
#include "stdafx.h"
#include "p6types.h"
#include "LeapSecondsInfo.h"
#include "TransitionTimeInfo.h"

class Timezone {
private:
	std::vector<LeapSecondsInfo>	leapSecondsVector;
	std::vector<P6::UINT8>			stdWallIndicators;
	std::vector<std::pair<time_t, unsigned int>>
									transitionTimesIndex;
	std::vector<TransitionTimeInfo> transitionTimesInfo;
	std::vector<P6::UINT8>			utcLocalIndicators;
public:
	Timezone(){}
	Timezone(std::vector<time_t> &transitionTimes, std::vector<unsigned int> &tti_indices, std::vector<LeapSecondsInfo> &leapSecondsVector,
			std::vector<P6::UINT8> &stdWallIndicators, std::vector<TransitionTimeInfo> &transitionTimesInfo,
			std::vector<P6::UINT8> &utcLocalIndicators){
		setLeapSecondsVector(leapSecondsVector);
		setStdWallIndicators(stdWallIndicators);
		setTransitionTimesInfo(transitionTimes, tti_indices, transitionTimesInfo);
		setUtcLocalIndicators(utcLocalIndicators);
	}
	virtual ~Timezone();

	/** Short comment: Retrieve a timezone class by name

		Retrieve a timezone by name for processing
		@param timezoneName Standard name of the timezone, which must be one of
		                    the names reported by getTimezoneNames()

		@return a timezone
	*/
	static const Timezone getTimezone(const std::string &timezoneName);

	/** Short comment: Retrieve valid timezone names

		Retrieve a vector of all valid timezone names

		@return a vector of timezone names
	*/
	static const std::vector<const std::string> getTimezoneNames();

	/** Short comment: Convert UTC time to this timezone

		Convert the UTC time to this timezone

		@param time the number of seconds UTC
		@return the local time in seconds
	*/
	long long fromUtc(time_t time);

	/** Short comment: Convert local time to UTC

		Convert local time to UTC. Note that this conversion
		may be imprecise because local times are not unique due to
		summer time and various other adjustments

		@param time the number of seconds since the Epoch local time
		@return the UTC time in seconds
	*/
	time_t toUtc(long long local);

	/** Short comment: Does this timezone have data loaded?

		@return true if the timezone data has not yet been loaded
	*/
	bool isEmpty(){
		return transitionTimesInfo.size()==0;
	}
protected:
	/** 
	  Short comment: Load the specified timezone from storage
	*/
	Timezone load(const std::string &tzName){
		Timezone tz;
		load(tzName, tz);
		return tz;
	}

	/** 
		Short comment: Load the specified timezone from storage into the specified timezone

		Load the timezone data from storage into the specified timezone
		@param tz the timezone to load into
	*/
	void load(const std::string &tzName, Timezone &tz);

	std::vector<LeapSecondsInfo> getLeapSecondsVector(){
		return leapSecondsVector;
	}

	void setLeapSecondsVector(std::vector<LeapSecondsInfo> &newVal){
		leapSecondsVector = newVal;
	}

	std::vector<P6::UINT8> getStdWallIndicators(){
		return stdWallIndicators;
	}

	void setStdWallIndicators(std::vector<P6::UINT8> &newVal){
		stdWallIndicators = newVal;
	}

	std::vector<P6::UINT8> getUtcLocalIndicators(){
		return utcLocalIndicators;
	}

	void setTransitionTimesInfo(std::vector<time_t> &times, std::vector<unsigned int> &indices, std::vector<TransitionTimeInfo> &newVal);

	void setUtcLocalIndicators(std::vector<P6::UINT8> &newVal){
		utcLocalIndicators = newVal;
	}
};

#endif /* TIMEZONE_H_ */
